package com.example.news.controller;

import com.example.news.pojo.form.BasePageQuery;
import com.example.news.pojo.vo.SearchArticleVo;
import com.example.news.pojo.vo.SearchRecordVo;
import com.example.news.service.SearchService;
import com.example.news.utils.result.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/search")
@Tag(name = "7.搜索模块")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @GetMapping("/records")
    @Operation(summary = "获取搜索记录(登录状态下才调用)")
    public PageResult<SearchRecordVo> getSearchRecords(@RequestHeader String token, @ParameterObject BasePageQuery basePageQuery) {
        return searchService.getSearchRecords(basePageQuery, token);
    }

    @GetMapping("/article")
    @Operation(summary = "搜索")
    public PageResult<SearchArticleVo> getSearchByKey(@RequestHeader(required = false) String token, @ParameterObject BasePageQuery basePageQuery,String key){
        return searchService.getSearchArticle(basePageQuery,key,token);
    }


}
